# -*- encoding: utf-8 -*-
'''
本脚本由诺言Nuoyan制作，用于批量制作自定义物品
'''

import os
import json


item_list = {
    't31:zzw': "蜘蛛网",
}
item_res_template = {
    "format_version": "1.10",
    "minecraft:item": {
        "description": {
            "identifier": "",
            "category": "items",
            "register_to_create_menu": True
        },
        "components": {
            "minecraft:icon": ""
        }
    }
}
item_beh_template = {
    "format_version": "1.10",
    "minecraft:item": {
        "description": {
            "identifier": "",
            "category": "items",
            "register_to_create_menu": True
        },
        "components": {
            "minecraft:max_stack_size": 64
        }
    }
}


root = __file__[:__file__.rindex("scripts")]


item_texture_path = root + r"plugins\t31PixelBreakout_Lobby\resource_packs\t31PixelBreakoutRes\textures\item_texture.json"
with open(item_texture_path, "r") as f:
    item_texture = json.load(f)
lang = ""


for n, cn in item_list.items():
    tex_path = ""
    for r, dirs, files in os.walk(root + r"plugins\t31PixelBreakout_Lobby\resource_packs\t31PixelBreakoutRes\textures\items"):
        for f in files:
            f = f.replace(".png", "")
            if f == n.split(":")[1]:
                tex_path = r[r.index("textures"):].replace("\\", "/") + "/" + f
                break
    if tex_path:
        item_texture['texture_data'][n] = {'textures': tex_path}
    else:
        print "[Missing] " + n
        continue

    item_res_template['minecraft:item']['description']['identifier'] = n
    item_res_template['minecraft:item']['components']['minecraft:icon'] = n
    json_name = n.replace("t31:", "")
    with open(root + r"plugins\t31PixelBreakout_Lobby\resource_packs\t31PixelBreakoutRes\netease_items_res\%s.json" % json_name, "w") as f:
        json.dump(item_res_template, f, indent=4, sort_keys=True, separators=(", ", ": "))

    item_beh_template['minecraft:item']['description']['identifier'] = n
    with open(root + r"plugins\t31PixelBreakout_Lobby\behavior_packs\t31PixelBreakoutBeh\netease_items_beh\%s.json" % json_name, "w") as f:
        json.dump(item_beh_template, f, indent=4, sort_keys=True, separators=(", ", ": "))

    lang += "item.%s.name=%s\n" % (n, cn)


with open(item_texture_path, "w") as f:
    json.dump(item_texture, f, indent=4, sort_keys=True, separators=(", ", ": "))
with open(root + r"plugins\t31PixelBreakout_Lobby\resource_packs\t31PixelBreakoutRes\texts\zh_CN.lang", "w") as f:
    f.write(lang)








